package com.collect.zambia.zhiScene.zhiCollection.zhiGroup.zhiPerformance.zhiHistory;

import android.content.Context;

import com.collect.zambia.zhiBase.BasePresenter;
import com.collect.zambia.zhiBase.BaseSubscriber;
import com.collect.zambia.zhiBean.zhiReceive.ZHIRPerfermanceGroupHistoryEntity;
import com.collect.zambia.zhiBean.zhiSend.ZHISPerfermanceEntity;
import com.collect.zambia.zhiNetApi.ZHIHttpApiProvider;
import com.collect.zambia.zhiNetApi.ZHIHttpResponse;
import com.collect.zambia.zhiUtils.RxSchedulers;

import java.util.ArrayList;

import javax.inject.Inject;

public class ZHIPerformanceGroupHistoryPresenter extends BasePresenter<ZHIPerformanceGroupHistoryContract.View> implements ZHIPerformanceGroupHistoryContract.Presenter {

    @Inject
    public ZHIPerformanceGroupHistoryPresenter() {

    }

    @Override
    public void getMyGroupHistoryBonus(Context context, ZHISPerfermanceEntity zhisPerfermanceEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ArrayList<ZHIRPerfermanceGroupHistoryEntity>>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ArrayList<ZHIRPerfermanceGroupHistoryEntity>>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ArrayList<ZHIRPerfermanceGroupHistoryEntity> zhirPerfermanceGroupHistoryEntityArrayList = (ArrayList<ZHIRPerfermanceGroupHistoryEntity>) object;
                            mView.onGetMyGroupHistoryBonus(zhirPerfermanceGroupHistoryEntityArrayList, zhisPerfermanceEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().getMyGroupHistoryBonus(zhisPerfermanceEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }
}
